#include <iostream>
#include <list>
using namespace std;
template <typename Container>
void display(const Container & con){
    for(auto elem : con){
        cout << elem << " ";
    }
    cout <<endl;
}
void test(){
   list<int> num = { 1,5,56,85,43,2,2,5,8,8,6,9,7,8,10 };
   cout << " list排序操作 " << endl;
   num.sort();
   display(num);
   cout << "list unique移除重复元素"<< endl;
   num.unique();
   display(num);
   cout << "list 逆置重复元素" <<endl;
   num.reverse();
   display(num);
   cout << "merge合并链表的函数" << endl;
   //合并的链表必须是有序的不然合并不了
   list <int> num2 = { 1,3,5,7,9 };
   num.reverse();
   num.merge(num2);
   display(num);
   cout << "splice从一个链表转移元素到另一个链表"<< endl;
   list <int> num3 = {100000,100001,100002};
   auto it = num.begin();
   ++it;
   ++it;
   num.splice(it,num3);//将num3的全部元素移动调用到splice链表对象的it的前面
   display(num);
   list <int> num4 = {0,1,0,5,8,9};
   auto it2 = num4.begin();
   ++it2;
   ++it2;
   num.splice(it,num4,it2);//将num4中的it2指向的元素插入num it指向的元素的前面
   display(num);
   auto it3 = num4.end();
   auto it4 = num4.begin();
   ++it4;
   ++it4;
   --it3;
   num.splice(it,num4,it4,it3);//将num4中的[it2,it3)的元素插入num it指向的元素前面
   display(num);


   cout <<"splice 自己的元素插入自己的前面" << endl;
   auto it5 = num.end();
   --it5;
   num.splice(it,num,it5);
   display(num);
}
int main()
{
    test();
    return 0;
}

